package models

import (
	"time"

	"github.com/go-xorm/xorm"
)

//varchar(25) notnull unique 'usr_name'
type User struct {
	UserId       uint      `xorm:"user_id notnull int pk autoincr"`
	Login        string    `xorm:"login notnull varchar(25) unique" valid:"required,length(3|25),alphanum"`
	Password     []byte    `xorm:"password notnull binary(48)" valid:"required"` // SHA384
	Name         string    `xorm:"name notnull varchar(25)" valid:"required,runelength(1|25)"`
	Email        string    `xorm:"email notnull varchar(75)" valid:"required,email"`
	Status       uint8     `xorm:"status notnull tinyint" valid:"required,matches(^(0|1)$)"`
	Avator       string    `xorm:"avator notnull varchar(75)" valid:"required,length(1|75)"`
	CreationDate time.Time `xorm:"creation_date notnull datetime"`
}

func (u *User) TableName() string {
	return "mm_users"
}

func (u *User) BeforeInsert() {
	u.CreationDate = time.Now().Local()
	// u.UpdatedUnix = u.CreatedUnix
}

func (u *User) BeforeUpdate() {
	// u.UpdatedUnix = time.Now().Unix()
}

func (u *User) AfterSet(colName string, _ xorm.Cell) {
	switch colName {
	case "created_unix":
		// u.Created = time.Unix(u.CreatedUnix, 0).Local()
	case "updated_unix":
		// u.Updated = time.Unix(u.UpdatedUnix, 0).Local()
	}
}

func (u *User) GetTickets() {

}

func (u *User) GetMasters() {

}

func (u *User) GetReviewers() {

}
